package com.tb.dubbo.controller;

import com.tb.dubbo.entity.Book;
import com.tb.dubbo.service.BookService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 作者：tb
 * 描述：todo
 * 日期：Created in 2022/4/6 14:09
 *
 * @Version 1.0
 */
@Controller
@RequestMapping("book")
public class BookController {
    @Autowired
    private BookService bookService;
    @RequestMapping("list")
    public String bookList(Model model){
        List<Book> bookList = bookService.findBookList();
        model.addAttribute("list",bookList);
        return "book_list";
    }
    @RequestMapping("toAdd")
    public String toAdd(){
        return "addBook";
    }
    @RequestMapping(value = "add",produces = "text/html;charset=utf-8")
    public String addBook(Model model,Book book){
        bookService.addBook(book);
        List<Book> bookList = bookService.findBookList();
        model.addAttribute("list",bookList);
        return "redirect:/book/list";
    }
}
